package com.nkl.admin.action;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.nkl.admin.manager.AdminManager;
import com.nkl.common.util.DateUtil;
import com.nkl.common.util.PaperUtil;
import com.nkl.page.domain.Activity;
import com.nkl.page.domain.College;
import com.nkl.page.domain.Equip;
import com.nkl.page.domain.Member;
import com.nkl.page.domain.News;
import com.nkl.page.domain.Picnews;
import com.nkl.page.domain.Sblog;
import com.nkl.page.domain.User;

@Controller
public class AdminAction{

	@Autowired
	AdminManager adminManager;
	public AdminManager getAdminManager() {
		return adminManager;
	}
	public void setAdminManager(AdminManager adminManager) {
		this.adminManager = adminManager;
	}
	String tip;
	
	/**
	 * @Title: saveAdmin
	 * @Description: 保存修改个人信息
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveAdmin.action")
	public String saveAdmin(User paramsUser,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//验证用户会话是否失效
			if (!validateAdmin(httpSession)) {
				return "loginTip";
			}
			 //保存修改个人信息
			adminManager.updateUser(paramsUser);
			//更新session
			User admin = new User();
			admin.setUser_id(paramsUser.getUser_id());
			admin = adminManager.getUser(admin);
			httpSession.setAttribute("admin", admin);

			setSuccessTip("编辑成功", "modifyInfo.jsp", model);
		} catch (Exception e) {
			e.printStackTrace();
			setErrorTip("编辑异常", "modifyInfo.jsp", model);
		}
		return "infoTip";
	}
	
	/**
	 * @Title: saveAdminPass
	 * @Description: 保存修改个人密码
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveAdminPass.action")
	public String saveAdminPass(User paramsUser,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//验证用户会话是否失效
			if (!validateAdmin(httpSession)) {
				return "loginTip";
			}
			User admin = (User)httpSession.getAttribute("admin");
			 //保存修改个人密码
			adminManager.updateUser(paramsUser);
			//更新session
			if (admin!=null) {
				admin.setUser_pass(paramsUser.getUser_pass());
				httpSession.setAttribute("admin", admin);
			}

			setSuccessTip("修改成功", "modifyPwd.jsp", model);
		} catch (Exception e) {
			setErrorTip("修改异常", "modifyPwd.jsp", model);
		}
		return "infoTip";
	}
	
	/**
	 * @Title: listUsers
	 * @Description: 查询用户
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listUsers.action")
	public String listUsers(User paramsUser,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			if (paramsUser==null) {
				paramsUser = new User();
			}
			//查询注册用户和社团管理员
			paramsUser.setUser_types("1,2");
			//设置分页信息
			paperUtil.setPagination(paramsUser);
			int[] sum={0};
			List<User> users = adminManager.listUsers(paramsUser,sum); 
			
			model.addAttribute("users", users);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询用户异常","main.jsp",model);
			return "infoTip";
		}
		
		return "userShow";
	}
	
	/**
	 * @Title: addUserShow
	 * @Description: 显示添加用户页面
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addUserShow.action")
	public String addUserShow(ModelMap model){
		return "userEdit";
	}
	
	/**
	 * @Title: addUser
	 * @Description: 添加用户
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addUser.action")
	public String addUser(User paramsUser,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//检查员工是否存在
			User user = new User();
			user.setUser_name(paramsUser.getUser_name());
			user = adminManager.getUser(user);
			if (user!=null) {
				model.addAttribute("tip","失败，该学号已经存在！");
				model.addAttribute("user", paramsUser);
				return "userEdit";
			}
			
			 //添加用户
			paramsUser.setUser_type(1);
			paramsUser.setReg_date(DateUtil.dateToDateString(new Date(), "yyyy-MM-dd HH:mm:ss"));
			adminManager.addUser(paramsUser);

			setSuccessTip("添加用户成功","Admin_listUsers.action",model);
		} catch (Exception e) {
			setErrorTip("添加用户异常","Admin_listUsers.action",model);
		}
		return "infoTip";
	}
	
	 
	/**
	 * @Title: editUser
	 * @Description: 编辑用户
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editUser.action")
	public String editUser(User paramsUser,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到用户
			User user = adminManager.getUser(paramsUser);
			model.addAttribute("user", user);
			
		} catch (Exception e) {
			setErrorTip("查询用户异常","Admin_listUsers.action",model);
			return "infoTip";
		}
		
		return "userEdit";
	}
	
	/**
	 * @Title: saveUser
	 * @Description: 保存编辑用户
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveUser.action")
	public String saveUser(User paramsUser,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑用户
			adminManager.updateUser(paramsUser);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("user", paramsUser);
			return "userEdit";
		}
		setSuccessTip("编辑用户成功","Admin_listUsers.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: delUsers
	 * @Description: 删除用户
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_delUsers.action")
	public String delUsers(User paramsUser,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除用户
			adminManager.delUsers(paramsUser);
			
		} catch (Exception e) {
			setErrorTip("删除用户异常","Admin_listUsers.action",model);
		}
		setSuccessTip("删除用户成功","Admin_listUsers.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listCollegeApproves
	 * @Description: 查询社团审批
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listCollegeApproves.action")
	public String listCollegeApproves(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			if (paramsCollege==null) {
				paramsCollege = new College();
			}
			//设置分页信息
			paperUtil.setPagination(paramsCollege);
			int[] sum={0};
			List<College> colleges = adminManager.listColleges(paramsCollege,sum); 
			
			model.addAttribute("colleges", colleges);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询社团审批异常","main.jsp",model);
			return "infoTip";
		}
		
		return "collegeApproveShow";
	}
	
	/**
	 * @Title: approveCollege
	 * @Description: 审批创建社团
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_approveCollege.action")
	public String approveCollege(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //创建社团审批
			adminManager.approveCollege(paramsCollege);
		} catch (Exception e) {
			setErrorTip("审批异常","Admin_listCollegeApproves.action",model);
		}
		setSuccessTip("审批成功","Admin_listCollegeApproves.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listColleges
	 * @Description: 管理查询社团
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listColleges.action")
	public String listColleges(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			if (paramsCollege==null) {
				paramsCollege = new College();
			}
			//设置分页信息
			paperUtil.setPagination(paramsCollege);
			//社长身份设置
			User admin = (User)httpSession.getAttribute("admin");
			paramsCollege.setUser_id(admin.getUser_id());
			int[] sum={0};
			List<College> colleges = adminManager.listColleges(paramsCollege,sum); 
			
			model.addAttribute("colleges", colleges);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询社团异常","main.jsp",model);
			return "infoTip";
		}
		
		return "collegeShow";
	}
	
	 
	/**
	 * @Title: editCollege
	 * @Description: 编辑社团
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editCollege.action")
	public String editCollege(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到社团
			College college = adminManager.getCollege(paramsCollege);
			model.addAttribute("college", college);
			
		} catch (Exception e) {
			setErrorTip("查询社团异常","Admin_listColleges.action",model);
			return "infoTip";
		}
		
		return "collegeEdit";
	}
	
	/**
	 * @Title: saveCollege
	 * @Description: 保存编辑社团
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveCollege.action")
	public String saveCollege(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑社团
			adminManager.updateCollege(paramsCollege);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("college", paramsCollege);
			return "collegeEdit";
		}
		setSuccessTip("编辑社团成功","Admin_listColleges.action",model);
		return "infoTip";
	}
	
	
	/**
	 * @Title: listCollegeNotes
	 * @Description: 查询社团简介
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listCollegeNotes.action")
	public String listCollegeNotes(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			if (paramsCollege==null) {
				paramsCollege = new College();
			}
			//设置分页信息
			paperUtil.setPagination(paramsCollege);
			int[] sum={0};
			List<College> colleges = adminManager.listColleges(paramsCollege,sum); 
			
			model.addAttribute("colleges", colleges);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询社团简介异常","main.jsp",model);
			return "infoTip";
		}
		
		return "collegeNoteShow";
	}
	
	/**
	 * @Title: editCollegeNote
	 * @Description: 编辑社团简介
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editCollegeNote.action")
	public String editCollegeNote(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到社团简介
			College college = adminManager.getCollege(paramsCollege);
			model.addAttribute("college", college);
			
		} catch (Exception e) {
			setErrorTip("查询社团简介异常","Admin_listCollegeNotes.action",model);
			return "infoTip";
		}
		
		return "collegeNoteEdit";
	}
	
	/**
	 * @Title: saveCollegeNote
	 * @Description: 保存编辑社团简介
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveCollegeNote.action")
	public String saveCollegeNote(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑社团简介
			adminManager.updateCollege(paramsCollege);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("college", paramsCollege);
			return "collegeEdit";
		}
		setSuccessTip("编辑社团简介成功","Admin_listCollegeNotes.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: delCollegeNotes
	 * @Description: 删除社团简介
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_delCollegeNotes.action")
	public String delCollegeNotes(College paramsCollege,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除社团
			adminManager.delColleges(paramsCollege);
			
		} catch (Exception e) {
			setErrorTip("删除社团异常","Admin_listCollegeNotes.action",model);
		}
		setSuccessTip("删除社团成功","Admin_listCollegeNotes.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listMembers
	 * @Description: 查询社团成员
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listMembers.action")
	public String listMembers(Member paramsMember,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			if (paramsMember==null) {
				paramsMember = new Member();
			}
			//设置分页信息
			paperUtil.setPagination(paramsMember);
			//社长身份设置
			User admin = (User)httpSession.getAttribute("admin");
			paramsMember.setAdmin_id(admin.getUser_id());
			int[] sum={0};
			List<Member> members = adminManager.listMembers(paramsMember,sum); 
			
			model.addAttribute("members", members);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询社团成员异常","main.jsp",model);
			return "infoTip";
		}
		
		return "memberShow";
	}
	
	/**
	 * @Title: approveMember
	 * @Description: 社团成员审批
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_approveMember.action")
	public String approveMember(Member paramsMember,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //社团成员审批
			adminManager.approveMember(paramsMember);
			
		} catch (Exception e) {
			setErrorTip("审批失败","Admin_listMembers.action",model);
		}
		setSuccessTip("审批成功","Admin_listMembers.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: delMembers
	 * @Description: 删除社团成员
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_delMembers.action")
	public String delMembers(Member paramsMember,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除社团成员
			adminManager.delMembers(paramsMember);
			
		} catch (Exception e) {
			setErrorTip("删除社团成员异常","Admin_listMembers.action",model);
		}
		setSuccessTip("删除社团成员成功","Admin_listMembers.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listEquips
	 * @Description: 查询学校器材
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listEquips.action")
	public String listEquips(Equip paramsEquip,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			if (paramsEquip==null) {
				paramsEquip = new Equip();
			}
			//设置分页信息
			paperUtil.setPagination(paramsEquip);
			int[] sum={0};
			List<Equip> equips = adminManager.listEquips(paramsEquip,sum); 
			
			model.addAttribute("equips", equips);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询学校器材异常","main.jsp",model);
			return "infoTip";
		}
		
		return "equipShow";
	}
	
	/**
	 * @Title: addEquipShow
	 * @Description: 显示添加学校器材页面
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addEquipShow.action")
	public String addEquipShow(Equip paramsEquip,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		return "equipEdit";
	}
	
	/**
	 * @Title: addEquip
	 * @Description: 添加学校器材
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addEquip.action")
	public String addEquip(Equip paramsEquip,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //添加学校器材
			adminManager.addEquip(paramsEquip);
			
		} catch (Exception e) {
			setErrorTip("添加学校器材异常","Admin_listEquips.action",model);
		}
		setSuccessTip("添加学校器材成功","Admin_listEquips.action",model);
		return "infoTip";
	}
	
	 
	/**
	 * @Title: editEquip
	 * @Description: 编辑学校器材
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editEquip.action")
	public String editEquip(Equip paramsEquip,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到学校器材
			Equip equip = adminManager.getEquip(paramsEquip);
			model.addAttribute("equip", equip);
			
		} catch (Exception e) {
			setErrorTip("查询学校器材异常","Admin_listEquips.action",model);
			return "infoTip";
		}
		
		return "equipEdit";
	}
	
	/**
	 * @Title: saveEquip
	 * @Description: 保存编辑学校器材
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveEquip.action")
	public String saveEquip(Equip paramsEquip,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑学校器材
			adminManager.updateEquip(paramsEquip);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("equip", paramsEquip);
			return "equipEdit";
		}
		setSuccessTip("编辑学校器材成功","Admin_listEquips.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: delEquips
	 * @Description: 删除学校器材
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_delEquips.action")
	public String delEquips(Equip paramsEquip,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除学校器材
			adminManager.delEquips(paramsEquip);
			
		} catch (Exception e) {
			setErrorTip("删除学校器材异常","Admin_listEquips.action",model);
		}
		setSuccessTip("删除学校器材成功","Admin_listEquips.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listPicnewss
	 * @Description: 查询图片新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listPicnewss.action")
	public String listPicnewss(Picnews paramsPicnews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//查询图片新闻资讯
			if (paramsPicnews==null) {
				paramsPicnews = new Picnews();
			}
			//设置分页信息
			paperUtil.setPagination(paramsPicnews);
			int[] sum = {0};
			List<Picnews> picnewss = adminManager.listPicnewss(paramsPicnews,sum); 
			
			model.addAttribute("picnewss", picnewss);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询图片新闻资讯异常","main.jsp",model);
			return "infoTip";
		}
		
		return "picnewsShow";
	}
	
	/**
	 * @Title: editPicnews
	 * @Description: 编辑图片新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editPicnews.action")
	public String editPicnews(Picnews paramsPicnews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到图片新闻资讯
			Picnews picnews = adminManager.getPicnews(paramsPicnews);
			model.addAttribute("picnews", picnews);
			
		} catch (Exception e) {
			setErrorTip("查询图片新闻资讯异常","Admin_listPicnewss.action",model);
			return "infoTip";
		}
		
		return "picnewsEdit";
	}
	
	/**
	 * @Title: savePicnews
	 * @Description: 保存编辑图片新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_savePicnews.action")
	public String savePicnews(Picnews paramsPicnews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑图片新闻资讯
			adminManager.updatePicnews(paramsPicnews);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("picnews", paramsPicnews);
			return "picnewsEdit";
		}
		setSuccessTip("编辑成功","Admin_listPicnewss.action",model);
		return "infoTip";
	}
	
	
	/**
	 * @Title: listActivitys
	 * @Description: 查询活动消息
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listActivitys.action")
	public String listActivitys(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//查询活动消息
			if (paramsActivity==null) {
				paramsActivity = new Activity();
			}
			//设置分页信息
			paperUtil.setPagination(paramsActivity);
			//用户身份判断
			User admin = (User) httpSession.getAttribute("admin");
			if (admin.getUser_type()==2) {
				//社团管理员
				paramsActivity.setUser_id(admin.getUser_id());
			}
			int[] sum={0};
			List<Activity> activitys = adminManager.listActivitys(paramsActivity,sum); 
			
			model.addAttribute("activitys", activitys);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询活动消息异常","main.jsp",model);
			return "infoTip";
		}
		
		return "activityShow";
	}
	
	/**
	 * @Title: approveActivity
	 * @Description: 社团活动审批
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_approveActivity.action")
	public String approveActivity(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//社团活动审批
			adminManager.approveActivity(paramsActivity);
			
		} catch (Exception e) {
			setErrorTip("审批异常","Admin_listActivitys.action",model);
		}
		setSuccessTip("审批成功","Admin_listActivitys.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: addActivityShow
	 * @Description: 显示添加活动消息页面
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addActivityShow.action")
	public String addActivityShow(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		//查询学校器材
		Equip equip = new Equip();
		equip.setStart(-1);
		List<Equip> equips = adminManager.listEquips(equip, null);
		StringBuilder sBuilder = new StringBuilder();
		if (equips!=null && equips.size()>0) {
			for (int i = 0; i < equips.size(); i++) {
				sBuilder.append(equips.get(i).getEquip_name());
				if (i!=equips.size()-1) {
					sBuilder.append("，");
				}
			}
		}
		model.addAttribute("equips", sBuilder.toString());
		
		return "activityEdit";
	}
	
	/**
	 * @Title: addActivity
	 * @Description: 添加活动消息
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addActivity.action")
	public String addActivity(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//用户身份判断
			User admin = (User) httpSession.getAttribute("admin");
			paramsActivity.setUser_id(admin.getUser_id());
			if (admin.getUser_type()==2) {
				//社团活动需审核
				paramsActivity.setActivity_flag(1);
				//社团活动
				paramsActivity.setActivity_type(1);
			}else {
				//校园活动无需审核
				paramsActivity.setActivity_flag(2);
				//校园活动
				paramsActivity.setActivity_type(2);
			}
			//添加活动消息
			adminManager.addActivity(paramsActivity);
			
		} catch (Exception e) {
			setErrorTip("添加活动消息异常","Admin_listActivitys.action",model);
		}
		setSuccessTip("添加成功","Admin_listActivitys.action",model);
		return "infoTip";
	}
	
	 
	/**
	 * @Title: editActivity
	 * @Description: 编辑活动消息
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editActivity.action")
	public String editActivity(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到活动消息
			Activity activity = adminManager.getActivity(paramsActivity);
			model.addAttribute("activity", activity);
			
			//查询学校器材
			Equip equip = new Equip();
			equip.setStart(-1);
			List<Equip> equips = adminManager.listEquips(equip, null);
			StringBuilder sBuilder = new StringBuilder();
			if (equips!=null && equips.size()>0) {
				for (int i = 0; i < equips.size(); i++) {
					sBuilder.append(equips.get(i).getEquip_name());
					if (i!=equips.size()-1) {
						sBuilder.append("，");
					}
				}
			}
			model.addAttribute("equips", sBuilder.toString());
			
		} catch (Exception e) {
			setErrorTip("查询活动消息异常","Admin_listActivitys.action",model);
			return "infoTip";
		}
		
		return "activityEdit";
	}
	
	/**
	 * @Title: saveActivity
	 * @Description: 保存编辑活动消息
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveActivity.action")
	public String saveActivity(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑活动消息
			adminManager.updateActivity(paramsActivity);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("activity", paramsActivity);
			
			//查询学校器材
			Equip equip = new Equip();
			equip.setStart(-1);
			List<Equip> equips = adminManager.listEquips(equip, null);
			StringBuilder sBuilder = new StringBuilder();
			if (equips!=null && equips.size()>0) {
				for (int i = 0; i < equips.size(); i++) {
					sBuilder.append(equips.get(i).getEquip_name());
					if (i!=equips.size()-1) {
						sBuilder.append("，");
					}
				}
			}
			model.addAttribute("equips", sBuilder.toString());
			
			return "activityEdit";
		}
		setSuccessTip("编辑成功","Admin_listActivitys.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: delActivitys
	 * @Description: 删除活动消息
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_delActivitys.action")
	public String delActivitys(Activity paramsActivity,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除活动消息
			adminManager.delActivitys(paramsActivity);
			
		} catch (Exception e) {
			setErrorTip("删除活动消息异常","Admin_listActivitys.action",model);
		}
		setSuccessTip("删除活动消息成功","Admin_listActivitys.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listNewss
	 * @Description: 查询新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listNewss.action")
	public String listNewss(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//查询新闻资讯
			if (paramsNews==null) {
				paramsNews = new News();
			}
			//设置分页信息
			paperUtil.setPagination(paramsNews);
			//用户身份判断
			User admin = (User) httpSession.getAttribute("admin");
			if (admin.getUser_type()==2) {
				//社团管理员
				paramsNews.setUser_id(admin.getUser_id());
			}
			int[] sum={0};
			List<News> newss = adminManager.listNewss(paramsNews,sum); 
			model.addAttribute("newss", newss);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询新闻资讯异常","main.jsp",model);
			return "infoTip";
		}
		
		return "newsShow";
	}
	
	/**
	 * @Title: approveNews
	 * @Description: 新闻资讯审批
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_approveNews.action")
	public String approveNews(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//社团活动审批
			adminManager.approveNews(paramsNews);
			
		} catch (Exception e) {
			setErrorTip("审批异常","Admin_listNewss.action",model);
		}
		setSuccessTip("审批成功","Admin_listNewss.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: addNewsShow
	 * @Description: 显示添加新闻资讯页面
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addNewsShow.action")
	public String addNewsShow(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		return "newsEdit";
	}
	
	/**
	 * @Title: addNews
	 * @Description: 添加新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_addNews.action")
	public String addNews(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//用户身份判断
			User admin = (User) httpSession.getAttribute("admin");
			paramsNews.setUser_id(admin.getUser_id());
			if (admin.getUser_type()==2) {
				//社团新闻需审核
				paramsNews.setNews_flag(1);
				//社团新闻
				paramsNews.setNews_type(1);
			}else {
				//校园新闻无需审核
				paramsNews.setNews_flag(2);
				//校园新闻
				paramsNews.setNews_type(2);
			}
			 //添加新闻资讯
			adminManager.addNews(paramsNews);
			
		} catch (Exception e) {
			setErrorTip("添加新闻异常","Admin_listNewss.action",model);
		}
		setSuccessTip("添加成功","Admin_listNewss.action",model);
		return "infoTip";
	}
	
	 
	/**
	 * @Title: editNews
	 * @Description: 编辑新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_editNews.action")
	public String editNews(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //得到新闻资讯
			News news = adminManager.getNews(paramsNews);
			model.addAttribute("news", news);
			
		} catch (Exception e) {
			setErrorTip("查询新闻异常","Admin_listNewss.action",model);
			return "infoTip";
		}
		
		return "newsEdit";
	}
	
	/**
	 * @Title: saveNews
	 * @Description: 保存编辑新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_saveNews.action")
	public String saveNews(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //保存编辑新闻资讯
			adminManager.updateNews(paramsNews);
			
		} catch (Exception e) {
			model.addAttribute("tip","编辑失败");
			model.addAttribute("news", paramsNews);
			return "newsEdit";
		}
		setSuccessTip("编辑成功","Admin_listNewss.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: delNewss
	 * @Description: 删除新闻资讯
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_delNewss.action")
	public String delNewss(News paramsNews,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除新闻资讯
			adminManager.delNewss(paramsNews);
			
		} catch (Exception e) {
			setErrorTip("删除异常","Admin_listNewss.action",model);
		}
		setSuccessTip("删除成功","Admin_listNewss.action",model);
		return "infoTip";
	}
	
	/**
	 * @Title: listSblogs
	 * @Description: 查询留言
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_listSblogs.action")
	public String listSblogs(Sblog paramsSblog,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			//查询留言
			if (paramsSblog==null) {
				paramsSblog = new Sblog();
			}
			paperUtil.setPagination(paramsSblog);
			int[] sum={0};
			List<Sblog> sblogs = adminManager.listSblogs(paramsSblog,sum); 
			
			model.addAttribute("sblogs", sblogs);
			paperUtil.setTotalCount(sum[0]);
			
		} catch (Exception e) {
			setErrorTip("查询异常","main.jsp",model);
			return "infoTip";
		}
		
		return "sblogShow";
	}
	
	/**
	 * @Title: approveSblog
	 * @Description: 审批留言
	 * @return String
	 */
	@RequestMapping(value="admin/Admin_approveSblog.action")
	public String approveSblog(Sblog paramsSblog,PaperUtil paperUtil,
			ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除留言
			adminManager.approveSblog(paramsSblog);

			setSuccessTip("审批成功","Admin_listSblogs.action",model);
		} catch (Exception e) {
			setErrorTip("审批异常","Admin_listSblogs.action",model);
		}
		return "infoTip";
	}
	
	/**
	 * @Title: delSblogs
	 * @Description: 删除留言
	 * @return String
	 */
		@RequestMapping(value="admin/Admin_delSblogs.action")
		public String delSblogs(Sblog paramsSblog,PaperUtil paperUtil,
				ModelMap model,HttpServletRequest request,HttpServletResponse response,HttpSession httpSession){
		try {
			 //删除留言
			adminManager.delSblogs(paramsSblog);

			setSuccessTip("删除成功","Admin_listSblogs.action",model);
		} catch (Exception e) {
			setErrorTip("删除异常","Admin_listSblogs.action",model);
		}
		return "infoTip";
	}
	
	
	
	private boolean validateAdmin(HttpSession httpSession){
		User admin = (User)httpSession.getAttribute("admin");
		if (admin!=null) {
			return true;
		}else {
			return false;
		}
	}
	
	private void setErrorTip(String tip,String url,ModelMap model){
		model.addAttribute("tipType", "error");
		model.addAttribute("tip", tip);
		model.addAttribute("url1", url);
		model.addAttribute("value1", "确 定");
	}
	
	private void setSuccessTip(String tip,String url,ModelMap model){
		model.addAttribute("tipType", "success");
		model.addAttribute("tip", tip);
		model.addAttribute("url1", url);
		model.addAttribute("value1", "确 定");
	}

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	
	
}
